package com.dkd.easybook.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dkd.common.annotation.DataScope;
import com.dkd.common.utils.EbUtils;
import com.dkd.easybook.domain.EbAttachments;
import com.dkd.easybook.mapper.EbAttachmentsMapper;
import com.dkd.easybook.service.IEbAttachmentsService;
import com.dkd.easybook.tools.EbTools;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 用户附件Service业务层处理
 *
 * @author itheima
 * @date 2024-12-12
 */
@Service
public class EbAttachmentsServiceImpl extends ServiceImpl<EbAttachmentsMapper, EbAttachments> implements IEbAttachmentsService {
    @Autowired
    private EbAttachmentsMapper ebAttachmentsMapper;
    /**
     * 查询用户附件
     *
     * @param attachmentId 用户附件主键
     * @return 用户附件
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public EbAttachments selectEbAttachmentsByAttachmentId(EbAttachments ebAttachments) {
        return ebAttachmentsMapper.selectEbAttachmentsByAttachmentId(ebAttachments);
    }
    /**
     * 查询用户附件列表
     *
     * @param ebAttachments 用户附件
     * @return 用户附件
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<EbAttachments> selectEbAttachmentsList(EbAttachments ebAttachments) {
        return ebAttachmentsMapper.selectEbAttachmentsList(ebAttachments);
    }
    /**
     * 新增用户附件
     *
     * @param ebAttachments 用户附件
     * @return 结果
     */
    @Override
    public int insertEbAttachments(EbAttachments ebAttachments) {
        EbUtils.setUserIdIfNull(ebAttachments,
                EbAttachments::getUserId,
                EbAttachments::setUserId);
        return ebAttachmentsMapper.insertEbAttachments(ebAttachments);
    }
    /**
     * 修改用户附件
     *
     * @param ebAttachments 用户附件
     * @return 结果
     */
    @Override
    public int updateEbAttachments(EbAttachments ebAttachments) {
        return ebAttachmentsMapper.updateEbAttachments(ebAttachments);
    }
    /**
     * 批量删除用户附件
     *
     * @param attachmentIds 需要删除的用户附件主键
     * @return 结果
     */
    @Override
    public int deleteEbAttachmentsByAttachmentIds(Long[] attachmentIds) {
        return ebAttachmentsMapper.deleteEbAttachmentsByAttachmentIds(attachmentIds);
    }
    /**
     * 删除用户附件信息
     *
     * @param attachmentId 用户附件主键
     * @return 结果
     */
    @Override
    public int deleteEbAttachmentsByAttachmentId(Long attachmentId) {
        return ebAttachmentsMapper.deleteEbAttachmentsByAttachmentId(attachmentId);
    }
    //参数为ids，查询附件列表 , 这个查询，数据权限没有实现，因为传递的参数不是对象，而是list，暂时没实现
    @Override
    public List<EbAttachments> selectEbAttachmentsListByIds(@Param("listEbAttachments") List<EbAttachments> listEbAttachments) {
        return ebAttachmentsMapper.selectEbAttachmentsListByIds(listEbAttachments);
    }
}
